SlideShare a Scribd company logo
Class No.35  Data Structures http://ecomputernotes.com
Skip List: Implementation   S 0 S 1 S 2 S 3   45 12 23 34   34   23 34 http://ecomputernotes.com
Implementation: TowerNode TowerNode will have array of next pointers. Actual number of next pointers will be decided by the random procedure. Define MAXLEVEL as an upper limit on number of levels in a node. 40 50 60 head tail 20 30 26 57 Tower Node http://ecomputernotes.com
Implementation: QuadNode A quad-node stores: item link to the node before link to the node after link to the node below link to the node above This will require copying the key (item) at different levels x quad-node http://ecomputernotes.com
Skip Lists with Quad Nodes 56 64 78  31 34 44  12 23 26    31  64  31 34  23 S 0 S 1 S 2 S 3 http://ecomputernotes.com
Performance of Skip Lists In a skip list with  n  items  The expected space used is proportional to  n . The expected search, insertion and deletion time is proportional to log  n . Skip lists are fast and simple to implement in practice http://ecomputernotes.com
Implementation 5: AVL tree An AVL tree, ordered by key insert : a standard insert; (log  n ) find : a standard find (without removing, of course); (log  n ) remove : a standard remove; (log  n ) key entry key entry key entry key entry and so on http://ecomputernotes.com
Anything better? So far we have find, remove and insert where time varies between constant log n . It would be nice to have all three as constant time operations! http://ecomputernotes.com
An  array  in which TableNodes are  not  stored consecutively Their place of storage is calculated using the key and a  hash function Keys and entries are scattered throughout the array. Implementation 6: Hashing key entry Key hash function array index 4 10 123 http://ecomputernotes.com
insert : calculate place of storage, insert TableNode; (1) find : calculate place of storage, retrieve entry; (1) remove : calculate place of storage, set it to null; (1) Hashing key entry 4 10 123 All are constant time (1) ! http://ecomputernotes.com
Hashing We use an array of some fixed size  T  to hold the data.  T  is typically prime. Each key is mapped into some number in the range  0  to  T-1  using a  hash function , which ideally should be efficient to compute. http://ecomputernotes.com
Example: fruits Suppose our hash function gave us the following values: hashCode("apple") = 5 hashCode("watermelon") = 3 hashCode("grapes") = 8 hashCode("cantaloupe") = 7 hashCode("kiwi") = 0 hashCode("strawberry") = 9 hashCode("mango") = 6 hashCode("banana") = 2 kiwi banana watermelon apple mango cantaloupe grapes strawberry 0 1 2 3 4 5 6 7 8 9 http://ecomputernotes.com
Example Store data in a table array: table[5] = "apple" table[3] = "watermelon" table[8] = "grapes"  table[7] = "cantaloupe" table[0] = "kiwi" table[9] = "strawberry"  table[6] = "mango" table[2] = "banana" kiwi banana watermelon apple mango cantaloupe grapes strawberry 0 1 2 3 4 5 6 7 8 9 http://ecomputernotes.com
Example Associative array: table["apple"] table["watermelon"]  table["grapes"]  table["cantaloupe"]  table["kiwi"]  table["strawberry"]  table["mango"]  table["banana"] kiwi banana watermelon apple mango cantaloupe grapes strawberry 0 1 2 3 4 5 6 7 8 9 http://ecomputernotes.com
Example Hash Functions If the keys are strings the hash function is some function of the characters in the strings. One possibility is to simply add the ASCII values of the characters: TableSize ABC h Example TableSize i str str h length i )% 67 66 65 ( ) ( : % ] [ ) ( 1 0                http://ecomputernotes.com
Finding the hash function int hashCode( char* s ) { int i, sum; sum = 0; for(i=0; i < strlen(s); i++ )  sum = sum + s[i];  //  ascii value return sum % TABLESIZE; } http://ecomputernotes.com
Example Hash Functions Another possibility is to convert the string into some number in some arbitrary base  b  ( b  also might be a prime number): T b b b ABC h Example T b i str str h length i i )% 67 66 65 ( ) ( : % ] [ ) ( 2 1 0 1 0                 http://ecomputernotes.com
Example Hash Functions If the keys are integers then  key%T  is generally a good hash function, unless the data has some undesirable features. For example, if  T = 10  and all keys end in zeros, then  key%T = 0  for all keys.  In general, to avoid situations like this,  T  should be a prime number. http://ecomputernotes.com

More Related Content

PPT
Computer notes - Hashing
PPT
Stack linked list
PPT
MEngine Overview
PPT
Stack and queue
PPT
computer notes - Data Structures - 8
PPTX
Project of data structure
PPTX
My lecture stack_queue_operation
PPTX
Functional linear data structures in f#
Computer notes - Hashing
Stack linked list
MEngine Overview
Stack and queue
computer notes - Data Structures - 8
Project of data structure
My lecture stack_queue_operation
Functional linear data structures in f#

What's hot (20)

PPT
Stacks and queue
PPT
Computer notes data structures - 9
PPT
Stacks and queues
PPT
Computer notes - Josephus Problem
PPTX
Data structures
PPTX
Data Structures - Lecture 6 [queues]
PPT
computer notes - Data Structures - 5
PPT
computer notes - Data Structures - 9
PPTX
Stack_Application_Infix_Prefix.pptx
PPT
Stack queue
PPTX
Stack of Data structure
PPT
Stacks, Queues, Deques
PPTX
Stack project
PPTX
STACKS IN DATASTRUCTURE
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPTX
The Stack And Recursion
PPTX
Stack data structure
PPTX
Stack - Data Structure
Stacks and queue
Computer notes data structures - 9
Stacks and queues
Computer notes - Josephus Problem
Data structures
Data Structures - Lecture 6 [queues]
computer notes - Data Structures - 5
computer notes - Data Structures - 9
Stack_Application_Infix_Prefix.pptx
Stack queue
Stack of Data structure
Stacks, Queues, Deques
Stack project
STACKS IN DATASTRUCTURE
STACK ( LIFO STRUCTURE) - Data Structure
The Stack And Recursion
Stack data structure
Stack - Data Structure
Ad

Viewers also liked (20)

PPT
computer notes - Data Structures - 27
PPT
computer notes - Data Structures - 36
PPT
computer notes - Data Structures - 13
PPT
computer notes - Data Structures - 10
PPT
computer notes - Data Structures - 3
PPT
computer notes - Data Structures - 15
PPT
computer notes - Data Structures - 39
PPT
computer notes - Data Structures - 33
PPT
computer notes - Data Structures - 19
PPT
computer notes - Data Structures - 2
PPT
computer notes - Data Structures - 25
PPT
computer notes - Data Structures - 17
PPT
computer notes - Data Structures - 7
PPT
computer notes - Data Structures - 34
PPT
computer notes - Data Structures - 26
PPT
computer notes - Data Structures - 1
PPT
computer notes - Data Structures - 18
PPT
computer notes - Data Structures - 29
PDF
computer notes - Deleting a node
PPT
computer notes - Data Structures - 23
computer notes - Data Structures - 27
computer notes - Data Structures - 36
computer notes - Data Structures - 13
computer notes - Data Structures - 10
computer notes - Data Structures - 3
computer notes - Data Structures - 15
computer notes - Data Structures - 39
computer notes - Data Structures - 33
computer notes - Data Structures - 19
computer notes - Data Structures - 2
computer notes - Data Structures - 25
computer notes - Data Structures - 17
computer notes - Data Structures - 7
computer notes - Data Structures - 34
computer notes - Data Structures - 26
computer notes - Data Structures - 1
computer notes - Data Structures - 18
computer notes - Data Structures - 29
computer notes - Deleting a node
computer notes - Data Structures - 23
Ad

Similar to computer notes - Data Structures - 35 (20)

PPTX
C++11 - A Change in Style - v2.0
PPTX
linkedlist.pptx
PPT
Data Structure In C#
PDF
C Programming Interview Questions
PDF
Esoteric Data structures
PDF
Arrays and strings in c++
PPT
01 stack 20160908_jintaek_seo
PPT
computer notes - Data Structures - 32
PDF
Real World Haskell: Lecture 7
PPTX
Library functions in c++
PPTX
DS Unit 1.pptx
PPT
Computer notes - Binary Search
PPTX
Lecture 02: Preliminaries of Data structure
PDF
Advanced perl finer points ,pack&amp;unpack,eval,files
PPTX
Intel JIT Talk
PDF
Making the most of 2.2
PPTX
CPP Homework Help
PPTX
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
ZIP
.Net 4.0 Threading and Parallel Programming
PPTX
unit-5 String Math Date Time AI presentation
C++11 - A Change in Style - v2.0
linkedlist.pptx
Data Structure In C#
C Programming Interview Questions
Esoteric Data structures
Arrays and strings in c++
01 stack 20160908_jintaek_seo
computer notes - Data Structures - 32
Real World Haskell: Lecture 7
Library functions in c++
DS Unit 1.pptx
Computer notes - Binary Search
Lecture 02: Preliminaries of Data structure
Advanced perl finer points ,pack&amp;unpack,eval,files
Intel JIT Talk
Making the most of 2.2
CPP Homework Help
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
.Net 4.0 Threading and Parallel Programming
unit-5 String Math Date Time AI presentation

More from ecomputernotes (20)

PPT
computer notes - Data Structures - 30
PPT
computer notes - Data Structures - 11
PPT
computer notes - Data Structures - 20
DOC
Computer notes - Including Constraints
DOC
Computer notes - Date time Functions
DOC
Computer notes - Subqueries
DOC
Computer notes - Other Database Objects
PPT
computer notes - Data Structures - 28
PPT
computer notes - Data Structures - 31
PPT
computer notes - Data Structures - 4
DOC
Computer notes - Advanced Subqueries
DOC
Computer notes - Aggregating Data Using Group Functions
PPT
computer notes - Data Structures - 16
PPT
computer notes - Data Structures - 22
DOC
Computer notes - Enhancements to the GROUP BY Clause
DOC
Computer notes - Manipulating Data
DOC
Computer notes - Writing Basic SQL SELECT Statements
PPT
computer notes - Data Structures - 14
DOC
Computer notes - Controlling User Access
DOC
Computer notes - Using SET Operator
computer notes - Data Structures - 30
computer notes - Data Structures - 11
computer notes - Data Structures - 20
Computer notes - Including Constraints
Computer notes - Date time Functions
Computer notes - Subqueries
Computer notes - Other Database Objects
computer notes - Data Structures - 28
computer notes - Data Structures - 31
computer notes - Data Structures - 4
Computer notes - Advanced Subqueries
Computer notes - Aggregating Data Using Group Functions
computer notes - Data Structures - 16
computer notes - Data Structures - 22
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Manipulating Data
Computer notes - Writing Basic SQL SELECT Statements
computer notes - Data Structures - 14
Computer notes - Controlling User Access
Computer notes - Using SET Operator

Recently uploaded (20)

PDF
STKI Israel Market Study 2025 version august
PPTX
The various Industrial Revolutions .pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
August Patch Tuesday
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
TLE Review Electricity (Electricity).pptx
STKI Israel Market Study 2025 version august
The various Industrial Revolutions .pptx
Assigned Numbers - 2025 - Bluetooth® Document
Hindi spoken digit analysis for native and non-native speakers
A comparative study of natural language inference in Swahili using monolingua...
Final SEM Unit 1 for mit wpu at pune .pptx
1 - Historical Antecedents, Social Consideration.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
NewMind AI Weekly Chronicles - August'25-Week II
cloud_computing_Infrastucture_as_cloud_p
A novel scalable deep ensemble learning framework for big data classification...
A contest of sentiment analysis: k-nearest neighbor versus neural network
August Patch Tuesday
1. Introduction to Computer Programming.pptx
Chapter 5: Probability Theory and Statistics
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
observCloud-Native Containerability and monitoring.pptx
O2C Customer Invoices to Receipt V15A.pptx
TLE Review Electricity (Electricity).pptx

computer notes - Data Structures - 35

  • 1. Class No.35 Data Structures http://ecomputernotes.com
  • 2. Skip List: Implementation   S 0 S 1 S 2 S 3   45 12 23 34   34   23 34 http://ecomputernotes.com
  • 3. Implementation: TowerNode TowerNode will have array of next pointers. Actual number of next pointers will be decided by the random procedure. Define MAXLEVEL as an upper limit on number of levels in a node. 40 50 60 head tail 20 30 26 57 Tower Node http://ecomputernotes.com
  • 4. Implementation: QuadNode A quad-node stores: item link to the node before link to the node after link to the node below link to the node above This will require copying the key (item) at different levels x quad-node http://ecomputernotes.com
  • 5. Skip Lists with Quad Nodes 56 64 78  31 34 44  12 23 26    31  64  31 34  23 S 0 S 1 S 2 S 3 http://ecomputernotes.com
  • 6. Performance of Skip Lists In a skip list with n items The expected space used is proportional to n . The expected search, insertion and deletion time is proportional to log n . Skip lists are fast and simple to implement in practice http://ecomputernotes.com
  • 7. Implementation 5: AVL tree An AVL tree, ordered by key insert : a standard insert; (log n ) find : a standard find (without removing, of course); (log n ) remove : a standard remove; (log n ) key entry key entry key entry key entry and so on http://ecomputernotes.com
  • 8. Anything better? So far we have find, remove and insert where time varies between constant log n . It would be nice to have all three as constant time operations! http://ecomputernotes.com
  • 9. An array in which TableNodes are not stored consecutively Their place of storage is calculated using the key and a hash function Keys and entries are scattered throughout the array. Implementation 6: Hashing key entry Key hash function array index 4 10 123 http://ecomputernotes.com
  • 10. insert : calculate place of storage, insert TableNode; (1) find : calculate place of storage, retrieve entry; (1) remove : calculate place of storage, set it to null; (1) Hashing key entry 4 10 123 All are constant time (1) ! http://ecomputernotes.com
  • 11. Hashing We use an array of some fixed size T to hold the data. T is typically prime. Each key is mapped into some number in the range 0 to T-1 using a hash function , which ideally should be efficient to compute. http://ecomputernotes.com
  • 12. Example: fruits Suppose our hash function gave us the following values: hashCode(&quot;apple&quot;) = 5 hashCode(&quot;watermelon&quot;) = 3 hashCode(&quot;grapes&quot;) = 8 hashCode(&quot;cantaloupe&quot;) = 7 hashCode(&quot;kiwi&quot;) = 0 hashCode(&quot;strawberry&quot;) = 9 hashCode(&quot;mango&quot;) = 6 hashCode(&quot;banana&quot;) = 2 kiwi banana watermelon apple mango cantaloupe grapes strawberry 0 1 2 3 4 5 6 7 8 9 http://ecomputernotes.com
  • 13. Example Store data in a table array: table[5] = &quot;apple&quot; table[3] = &quot;watermelon&quot; table[8] = &quot;grapes&quot; table[7] = &quot;cantaloupe&quot; table[0] = &quot;kiwi&quot; table[9] = &quot;strawberry&quot; table[6] = &quot;mango&quot; table[2] = &quot;banana&quot; kiwi banana watermelon apple mango cantaloupe grapes strawberry 0 1 2 3 4 5 6 7 8 9 http://ecomputernotes.com
  • 14. Example Associative array: table[&quot;apple&quot;] table[&quot;watermelon&quot;] table[&quot;grapes&quot;] table[&quot;cantaloupe&quot;] table[&quot;kiwi&quot;] table[&quot;strawberry&quot;] table[&quot;mango&quot;] table[&quot;banana&quot;] kiwi banana watermelon apple mango cantaloupe grapes strawberry 0 1 2 3 4 5 6 7 8 9 http://ecomputernotes.com
  • 15. Example Hash Functions If the keys are strings the hash function is some function of the characters in the strings. One possibility is to simply add the ASCII values of the characters: TableSize ABC h Example TableSize i str str h length i )% 67 66 65 ( ) ( : % ] [ ) ( 1 0                http://ecomputernotes.com
  • 16. Finding the hash function int hashCode( char* s ) { int i, sum; sum = 0; for(i=0; i < strlen(s); i++ ) sum = sum + s[i]; // ascii value return sum % TABLESIZE; } http://ecomputernotes.com
  • 17. Example Hash Functions Another possibility is to convert the string into some number in some arbitrary base b ( b also might be a prime number): T b b b ABC h Example T b i str str h length i i )% 67 66 65 ( ) ( : % ] [ ) ( 2 1 0 1 0                 http://ecomputernotes.com
  • 18. Example Hash Functions If the keys are integers then key%T is generally a good hash function, unless the data has some undesirable features. For example, if T = 10 and all keys end in zeros, then key%T = 0 for all keys. In general, to avoid situations like this, T should be a prime number. http://ecomputernotes.com

Editor's Notes

  • #3: Start of 41.
  • #5: Start lecture 41
  • #19: End of lecture 41. Start of lecture 42.